package com.shenyong.ladmin.controller;

import com.shenyong.entity.Menu;
import com.shenyong.ladmin.logConfig.Log;
import com.shenyong.ladmin.logConfig.OperationType;
import com.shenyong.ladmin.mapper.MenuMapper;
import com.shenyong.ladmin.service.MenuService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author
 * @site
 * @company
 * @create
 * 后台权限树
 */
@RestController
public class MenuController {
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private MenuService menuService;
    @RequiresAuthentication
    @RequestMapping("/getTree")
    public List<Map<String, Object>> getTree(Integer user_id){
        return menuService.getTree(user_id);
    }

    @RequestMapping("/getTreeTable")
    public Map<String,Object> getTreeTable(){
        List<Map<String, Object>> listmap=new ArrayList<Map<String, Object>>();
        Map<String,Object> map1=new HashMap<String,Object>();
        List<com.shenyong.ladmin.entity.Menu> lis=menuMapper.getTreeOne();
        for (int i=0;i<menuService.getTreeTable().size();i++){
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("id",menuService.getTreeTable().get(i).getMenu_id());
            map.put("name",menuService.getTreeTable().get(i).getMenu_name());
            map.put("url",menuService.getTreeTable().get(i).getMenu_url());
            map.put("pid",menuService.getTreeTable().get(i).getMenu_menuId());
/*            for(int j=0;j<lis.size();j++){
                if(menuService.getTreeTable().get(i).getMenu_name()==lis.get(j).getMenu_name()){
                    map.put("LAY_CHECKED",true);
                }
            }*/
            listmap.add(map);
        }
        map1.put("code",0);
        map1.put("msg","ok");
        map1.put("data",listmap);
        map1.put("count",menuService.getTreeTable().size());
        return map1;
    }
    @RequestMapping("/getTreeTable1")
    public Map<String,Object> getTreeTable1(){
        List<Map<String, Object>> listmap=new ArrayList<Map<String, Object>>();
        Map<String,Object> map1=new HashMap<String,Object>();
        for (int i=0;i<menuMapper.getTreeOne().size();i++){
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("id",menuMapper.getTreeOne().get(i).getMenu_id());
            map.put("name",menuMapper.getTreeOne().get(i).getMenu_name());
            map.put("url",menuMapper.getTreeOne().get(i).getMenu_url());
            map.put("pid",menuMapper.getTreeOne().get(i).getMenu_menuId());
            listmap.add(map);
        }
        map1.put("code",0);
        map1.put("msg","ok");
        map1.put("data",listmap);
        map1.put("count",menuMapper.getTreeOne().size());
        return map1;
    }
    @RequiresAuthentication
    @Log(describe = "添加权限模块",operationType= OperationType.INSERT)
    @RequestMapping("/saveTreeTable")
    public int saveTreeTable(com.shenyong.ladmin.entity.Menu menu){
        return menuService.saveTreeTable(menu);
    }
    @RequiresAuthentication
    @Log(describe = "删除模块",operationType= OperationType.UPDATE)
    @RequestMapping("/deleteTreeTable")
    public int deleteTreeTable(int id){
        return menuService.deleteTreeTable(id);
    }
    @RequiresAuthentication
    @Log(describe = "修改权限模块信息",operationType= OperationType.UPDATE)
    @RequestMapping("/updateTreeTable")
    public int updateTreeTable(com.shenyong.ladmin.entity.Menu menu){
        return menuService.updateTreeTable(menu);
    }
    @RequestMapping("/menuload")
    public Object menuload(){
       return menuService.menuload(1);
    }

}
